<?php  ?>
<div class="row full_width">
    <div class="large-12 columns">

    </div>
</div>

<div class="row full_width">

    <div class="large-2 columns nav__">
        <br />
        <ul class="side-nav nav_ panel">
            <li><h5>Action</h5></li>
            <li class="divider"></li>
            <li class=""><a href="#" data-reveal-id="myModal">Add department</a></li>
            <li class=""><a href="<?php echo site_url('information/logout'); ?>">Log-out</a></li>
        </ul>
    </div>
    <br />

    <div class="large-9 push-1 columns panel">
        <div>
            <h5 class="left">Manage Departments</h5>
            <div class="right">
                <?php echo form_open('search/people'); ?>
                    <div class="row collapse">

                        <div class="large-3 columns ">
                            <label class="prefix" for="search">Search:</label>
                        </div>
                        <div class="large-7 columns">
                            <input id="search" name="search" type="text" />
                        </div>
                        <div class="large-2 columns">
                            <input class="postfix button" type="submit" value="Go"/>
                        </div>

                    </div>
                <?php echo form_close(); ?>
            </div>
        </div>

        <hr />

        <div class="row collapse">

            <?php
            //echo var_dump(!empty($user_dept) and $user_dept[0]['user_id'] != null);
            if(!empty($user_dept) and $user_dept[0]['user_id'] != null){ ?>

            <table width="100%">
                <thead>
                <tr>
                    <th>Department</th>
                    <th width="300">Dean</th>
                    <th width="150"># of Members</th>
                    <th width="150">Actions</th>
                </tr>
                </thead>
                <tbody>
                <?php
                //var_dump($user_dept);
                for($i = 0; $i < count($user_dept) ; $i++):
                    ?>

                    <tr>
                        <td><?php echo $user_dept[$i]['coll_name'];  ?></td>

                        <td>

                            <?php if(isset($user_dept[$i]['user_id']) and $user_dept[$i]['type_no'] == 1){ ?>
                                <a href='<?php echo site_url('information/view_user'). '/' . $user_dept[$i]['user_id']; ?>'>
                                    <?php echo $user_dept[$i]['fname'] . " " . $user_dept[$i]['middle_initial'] . ". " . $user_dept[$i]['lname'];?>
                                </a>
                            <?php }

                            else {?>
                                None - <a href="#" data-reveal-id="collegeModal<?php echo $user_dept[$i]['coll_id']; ?>">Add Dean</a>
                            <?php } ?>

                        </td>

                        <td><?php echo $user_dept[$i]['total_members']; ?></td>
                        <td>
                            <a href="#" data-reveal-id="editModal<?php echo $user_dept[$i]['coll_id']; ?>">Edit</a>
                            <a href="<?php echo site_url('manage_department/delete_dept')."/".$user_dept[$i]['coll_id']; ?>">Delete</a>
                        </td>
                    </tr>

                <?php endfor ?>
                </tbody>
            </table>
            <p><?php echo $links; ?></p>

            <?php }
            else{ ?>
                <p>Colleges are empty.</p>
            <?php } ?>

        </div>
    </div>

    <div id="myModal" class="reveal-modal small" data-reveal>
        <h2>Add a College and Dean</h2>
        <hr />

        <h6><strong>College</strong></h6>

        <?php echo validation_errors(); ?>

        <?php echo form_open('manage_department/add_college', 'data-abide') ?>

        <div class="row">
            <div class="large-4 columns">
                <label class="inline" for="college_name">College name:<br /><small>*Required</small></label>
            </div>
            <div class="large-5 columns">
                <input type="text" id="college_name" name="college_name" value="" required=""/>
                <small class="error">College name is required.</small>
            </div>
            <div class="large-3 columns"></div>
        </div>

        <hr />

        <h6><strong>Account</strong></h6>

        <div class="row">
            <div class="large-4 columns">
                <label class="inline" for="user">Username:<br /><small>*Required</small></label>
            </div>
            <div class="large-5 columns">
                <input type="text" id="user" name="user" value="" required=""/>
                <small class="error">Username is required.</small>
            </div>
            <div class="large-3 columns"></div>
        </div>

        <div class="row">
            <div class="large-4 columns">
                <label class="inline" for="pass">Password:</span></label>
            </div>
            <div class="large-5 columns">
                <input type="password" id="pass" name="pass" value="" />
                <p style="font-size:13px; color:indianred;">* If left blank, the default password will be added.</p>
            </div>
            <div class="large-3 columns"></div>
        </div>

        <hr />

        <h6><strong>Profile</strong></h6>

        <div class="row">
            <div class="large-4 columns">
                <label class="inline" for="fname">First Name:<br /><small>*Required</small></label>
            </div>
            <div class="large-5 columns">
                <input type="text" id="fname" name="fname" value="" required pattern="alpha"/>
                <small class="error">Only letters are allowed and is required.</small>
            </div>
            <div class="large-3 columns"></div>
        </div>

        <div class="row">
            <div class="large-4 columns">
                <label class="inline" for="middle_initial">Middle Initial:<br /><small>*Required</small></label>
            </div>
            <div class="large-5 columns">
                <input type="text" id="middle_initial" name="middle_initial" value="" required pattern="alpha"/>
                <small class="error">Only letters are allowed and is required.</small>
            </div>
            <div class="large-3 columns"></div>
        </div>

        <div class="row">
            <div class="large-4 columns">
                <label class="inline" for="lname">Last Name:<br /><small>*Required</small></label>
            </div>
            <div class="large-5 columns">
                <input type="text" id="lname" name="lname" value="" required pattern="alpha"/>
                <small class="error">Only letters are allowed and is required.</small>
            </div>
            <div class="large-3 columns"></div>
        </div>

        <input class="button small" type="submit" name="submit" value="Submit" />

        <?php echo form_close(); ?>

        <a class="close-reveal-modal">&#215;</a>
    </div>

    <?php

        for($i = 0; $i < count($user_dept) ; $i++):

    ?>

    <div id="collegeModal<?php echo $user_dept[$i]['coll_id']; ?>" class="reveal-modal small" data-reveal>
        <h2>Add a Dean</h2>
        <hr />

        <?php echo validation_errors(); ?>

        <?php echo form_open('manage_department/add_dean', 'data-abide') ?>

        <h6><strong>Account</strong></h6>

        <div class="row">
            <div class="large-4 columns">
                <label class="inline" for="dean_user">Username:<br /><small>*Required</small></label>
            </div>
            <div class="large-5 columns">
                <input type="text" id="dean_user" name="dean_user" value="" required=""/>
                <small class="error">Username is required.</small>
            </div>
            <div class="large-3 columns"></div>
        </div>

        <div class="row">
            <div class="large-4 columns">
                <label class="inline" for="dean_pass">Password:</span></label>
            </div>
            <div class="large-5 columns">
                <input type="password" id="dean_pass" name="dean_pass" value="" />
                <p style="font-size:13px; color:indianred;">* If left blank, the default password will be added.</p>
            </div>
            <div class="large-3 columns"></div>
        </div>

        <hr />

        <h6><strong>Profile</strong></h6>

        <div class="row">
            <div class="large-4 columns">
                <label class="inline" for="dean_fname">First Name:<br /><small>*Required</small></label>
            </div>
            <div class="large-5 columns">
                <input type="text" id="dean_fname" name="dean_fname" value="" required pattern="name_space"/>
                <small class="error">Only letters are allowed and is required.</small>
            </div>
            <div class="large-3 columns"></div>
        </div>

        <div class="row">
            <div class="large-4 columns">
                <label class="inline" for="dean_middle_initial">Middle Initial:<br /><small>*Required</small></label>
            </div>
            <div class="large-5 columns">
                <input type="text" id="dean_middle_initial" name="dean_middle_initial" value="" maxlength="1" required pattern="alpha"/>
                <small class="error">Only letters are allowed and is required.</small>
            </div>
            <div class="large-3 columns"></div>
        </div>

        <div class="row">
            <div class="large-4 columns">
                <label class="inline" for="dean_lname">Last Name:<br /><small>*Required</small></label>
            </div>
            <div class="large-5 columns">
                <input type="text" id="dean_lname" name="dean_lname" value="" required pattern="name_space"/>
                <small class="error">Only letters are allowed and is required.</small>
            </div>
            <div class="large-3 columns"></div>
        </div>

        <input type="hidden" name="college_id" value="<?php echo $user_dept[$i]['coll_id']; ?>" />

        <input class="button small" type="submit" name="submit" value="Submit" />

        <?php echo form_close(); ?>

        <a class="close-reveal-modal">&#215;</a>
    </div>

    <?php
        endfor
    ?>

    <?php

        for($i = 0; $i < count($user_dept) ; $i++):

    ?>

        <div id="editModal<?php echo $user_dept[$i]['coll_id']; ?>" class="reveal-modal small" data-reveal>
            <h2>Edit a College</h2>
            <hr />

            <?php echo validation_errors(); ?>

            <?php echo form_open('manage_department/edit_college', 'data-abide') ?>

            <div class="row">
                <div class="large-4 columns">
                    <label class="inline" for="edit_college">College Name:<br /><small>*Required</small></label>
                </div>
                <div class="large-5 columns">
                    <input type="text" id="edit_college" name="edit_college" value="<?php echo $user_dept[$i]['coll_name']; ?>" required=""/>
                    <small class="error">Username is required.</small>
                </div>
                <div class="large-3 columns"></div>
            </div>

            <input type="hidden" name="college_id" value="<?php echo $user_dept[$i]['coll_id']; ?>" />

            <input class="button small" type="submit" name="submit" value="Submit" />

            <?php echo form_close(); ?>

            <a class="close-reveal-modal">&#215;</a>
        </div>

    <?php
        endfor
    ?>

</div>